package com.graduation.roombooking.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.graduation.roombooking.mapper.RoomMapper;
import com.graduation.roombooking.pojo.Room;
import com.graduation.roombooking.service.IRoomService;
import com.graduation.roombooking.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhaoXinyi
 * @since 2022-05-04
 */
@Service
public class RoomServiceImpl extends ServiceImpl<RoomMapper, Room> implements IRoomService {

    @Autowired
    private RoomMapper roomMapper;

    @Override
    public RespBean getList(String companyName) {
        return RespBean.success(roomMapper.getList(companyName));
    }

    @Override
    public RespBean addOne(AddRoomVo addRoomVo, String companyName) {

        Map<String,Object> map=new HashMap<>();
        map.put("addRoomVo",addRoomVo);
        map.put("companyName",companyName);

        if(roomMapper.addOne(addRoomVo,companyName)<1){
            return RespBean.error(RespBeanEnum.INSERT_ERROR,"添加失败，请检查数据输入是否规范");
        }
        return RespBean.success();
    }

    @Override
    public RespBean updateBaseInfo(UpdateRoomBaseInfoVo updateRoomBaseInfoVo, String companyName) {
        if(roomMapper.updateBaseInfo(updateRoomBaseInfoVo,companyName)<1){
            return RespBean.error(RespBeanEnum.UPDATE_ERROR,"添加失败，请检查数据数据是否输入规范或者该会议室是否属于本部门");
        }
        return RespBean.success();
    }

    @Override
    public RespBean deleteOne(Integer id, String companyName) {
        if(roomMapper.deleteOne(id,companyName)<1){
            return RespBean.error(RespBeanEnum.UPDATE_ERROR,"删除失败，请检查该会议室是否属于本部门");
        }
        return RespBean.success();
    }

    @Override
    public RespBean unionQuery(RoomUnionQuery roomUnionQuery, String companyName) {
        return RespBean.success(roomMapper.unionQuery(roomUnionQuery,companyName));
    }

    @Override
    public RespBean sysUpdateStatus(Integer id) {
        if(roomMapper.sysUpdateStatus(id)<1){
            return RespBean.error(RespBeanEnum.UPDATE_ERROR,"修改失败，请查看该条数据是否存在");
        }
        return RespBean.success();
    }

    @Override
    public RespBean getAppletRoomList(AppletRoomVo appletRoomVo) {
        return RespBean.success(roomMapper.getAppletRoomList(appletRoomVo));
    }

    @Override
    public RespBean getRoomInfo(RoomInfoVo roomInfoVo) {
        return RespBean.success(roomMapper.selectById(roomInfoVo.getRoomId()));
    }
}
